<%@ page contentType="text/html; charset=UTF-8"%>
<%@include file="/html/portlet/chart/admin/init.jsp"%>

<%
    String keywords = ParamUtil.getString(request, "keywords");
List<Option> optiones = null;
if(Validator.isNotNull(keywords)){
	SearchContext searchContext = SearchContextFactory
			.getInstance(request);
			
			searchContext.setKeywords(keywords);
			searchContext.setAttribute("paginationType", "more");
		//	searchContext.gets.setStart(0);
			//searchContext.setEnd(10);
			
			Indexer indexer = IndexerRegistryUtil.getIndexer(Option.class);
			
			Hits hits = indexer.search(searchContext);
			
			optiones = new ArrayList<Option>();
			
			for (int i = 0; i < hits.getDocs().length; i++) {
			        Document doc = hits.doc(i);
			
			        long optionId = GetterUtil
			        .getLong(doc.get(Field.ENTRY_CLASS_PK));
			
			        Option option = null;
			
			        try {
			        	option = OptionLocalServiceUtil.getOption(optionId);
			        } catch (PortalException pe) {
			                _log.error(pe.getLocalizedMessage());
			        } catch (SystemException se) {
			                _log.error(se.getLocalizedMessage());
			        }
			
			        optiones.add(option);
			}
}
%>


<liferay-ui:search-container  rowChecker="<%= new RowChecker(renderResponse) %>"  emptyResultsMessage="no-entries-were-found">
	<liferay-ui:search-container-results
		results="<%=Validator.isNotNull(keywords)?optiones:OptionLocalServiceUtil.getOptions(searchContainer.getStart(), searchContainer.getEnd())%>"
		total="<%= Validator.isNotNull(keywords)?optiones.size():OptionLocalServiceUtil.getOptionsCount() %>" />
		
	<liferay-util:include page="/html/portlet/chart/admin/toolbar.jsp" servletContext="<%= application %>" />
	
	<liferay-ui:search-container-row
		className="cn.shuto.liferay.plugin.chart.service.model.Option"
		keyProperty="optionId" modelVar="option" escapedModel="<%=true%>">
		<portlet:renderURL var="rowURL">
			<portlet:param name="optionId"
				value="<%=String.valueOf(option.getOptionId()) %>" />
			<portlet:param name="mvcPath"
				value="/html/portlet/chart/admin/edit_chartoption.jsp" />
			<portlet:param name="redirect" value="<%= currentURL %>" />
		</portlet:renderURL>
		<liferay-ui:search-container-column-text name="chart.option.id"
					property="optionId" href="<%= rowURL %>"/>
		<liferay-ui:search-container-column-text name="name"
			property="name" href="<%= rowURL %>"/>
		<liferay-ui:search-container-column-text name="description"
			property="description" href="<%= rowURL %>"/>
		<liferay-ui:search-container-column-date name="modified-date" property="modifiedDate" href="<%= rowURL %>"/>
		<liferay-ui:search-container-column-text name="author" property="userName" href="<%= rowURL %>"/>
		<liferay-ui:search-container-column-date name="create-date" property="createDate" href="<%= rowURL %>"/>
		
	<liferay-ui:search-container-column-jsp
	            path="/html/portlet/chart/admin/chartoption_actions.jsp"
	            align="right" />
	</liferay-ui:search-container-row>

	
	<liferay-ui:search-iterator />
</liferay-ui:search-container>

<%!
        private static Log _log = LogFactoryUtil.getLog("html.portlet.chart.admin.view_jsp");
%>